package com.artPreter.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.artPreter.pojo.Picture;
import com.artPreter.pojo.Result;
import com.artPreter.service.IPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 图片表 前端控制器
 * </p>
 *
 * @author jarvis
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/picture")
public class PictureController {

    @Autowired
    private IPictureService pictureService;

    /**
     * 添加图片
     * @param
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Picture picture){
        pictureService.add(picture);
        return Result.success();
    }

    /**
     * 添加到图片关联表
     * @param picture
     * @return
     */
    @PostMapping("/addToRelative")
    public Result addToRelative(@RequestBody Picture picture){
        pictureService.addToRelative(picture);
        return Result.success();
    }

    /**
     * 编辑图片
     * @param
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody Picture picture){
        pictureService.edit(picture);
        return Result.success();
    }

    /**
     * 删除图片
     * @param
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Picture picture){
        pictureService.delete(picture);
        return Result.success();
    }

    @PostMapping("/removePictureRelative")
    public Result removePictureRelative(@RequestBody Picture picture){
        pictureService.removePictureRelative(picture);
        return Result.success();
    }

    /**
     * 图片分页
     * @param currentPage
     * @param size
     * @param
     * @return
     */
    @PostMapping("/getPage")
    public Result getPage(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Picture picture){
        IPage<Picture> pictureIPage = pictureService.getPage(currentPage,size,picture);
        return Result.success(pictureIPage);
    }

    @PostMapping("/getPageNoRelative")
    public Result getPageNoRelative(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Picture picture){
        IPage<Picture> pictureIPage = pictureService.getPageNoRelative(currentPage,size,picture);
        return Result.success(pictureIPage);
    }

    @PostMapping("/getPageRelative")
    public Result getPageRelative(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value = "size",defaultValue = "10") Integer size, @RequestBody Picture picture){
        IPage<Picture> pictureIPage = pictureService.getPageRelative(currentPage,size,picture);
        return Result.success(pictureIPage);
    }

}
